package com.jinandi.app.domain;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.security.core.GrantedAuthority;

/**
 * 
 * <角色和用户关系表>
 * @author CGC
 * @version [记录版本号, 2013-4-17]
 */
@Entity
@Table(name = "JND_ROLE")
public class Role extends ManagedIdentityDomainObject<Role> implements
		GrantedAuthority {

	private static final long serialVersionUID = -3666504755111449432L;

	private User user; //关联用户id

	private Authorit authorit; //关联权限id

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "authorit_id",nullable = false)
	public Authorit getAuthorit() {
		return authorit;
	}

	public void setAuthorit(Authorit authorit) {
		this.authorit = authorit;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id",nullable = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setAuthority(String authority) {
	}

	@Override
	public String getAuthority() {
		return authorit.getAuthority();
	}
}
